<?php

class Contest_Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

	protected $_name = 'contest';

	function _initAcl()
	{
		$registry = Zend_Registry::getInstance();
		/**
		 * @var $acl Zend_Acl
		 */
		$acl = $registry->get('acl');
		$this->_initIndexAcl($acl);
		$this->_initEntryAcl($acl);
		$this->_initManageAcl($acl);
		$this->_initReportAcl($acl);
		$this->_initShareAcl($acl);
	}

	/**
	 *
	 * @param Zend_Acl $acl
	 */
	private function _initIndexAcl($acl)
	{
		$resource_name = $this->_name . ':index';
		$acl->addResource($resource_name);
		$arrGuest = array(
			'index',
			'share',
            'invite'
		);
		$arrUser = array_merge(
				array(
                    'notify'
				), $arrGuest
		);
		$acl->allow(Core_Role::ROLE_GUEST, $resource_name, $arrGuest);

		$acl->allow(Core_Role::ROLE_USER, $resource_name, $arrUser);
	}

	private function _initEntryAcl($acl)
	{
		$resource_name = $this->_name . ':entry';
		$acl->addResource($resource_name);
		
		$arrUser = array(
			'index',
			'list',
			'approve',
			'reject',
			'edit',
			'detail',
            'approvelist',
            'rejectlist',
			'export-voters'
		);
		
		$arrGuest = array(
			'view'
		);
		$acl->allow(Core_Role::ROLE_GUEST, $resource_name, $arrGuest);
		$acl->allow(Core_Role::ROLE_USER, $resource_name, $arrUser);
	}

	private function _initReportAcl($acl)
	{
		$resource_name = $this->_name . ':report';
		$acl->addResource($resource_name);
		
		$arrUser = array(
			'index',			
			'export-entries',
			'export-participants',
			'export-registrants',
			'export-voters',
			'chart-data',
            'export-all'
		);
		
		$acl->allow(Core_Role::ROLE_USER, $resource_name, $arrUser);
	}
	/**
	 *
	 * @param Zend_Acl $acl
	 */
	private function _initManageAcl($acl)
	{
		$resource_name = $this->_name . ':manage';
		$acl->addResource($resource_name);
		$arrUser = array(
			'index',
			'form',
			'create-basic',
			'do-create-basic',
			'create-entry',
			'do-create-entry',
			'setting-theme',
			'do-setting-theme',
			'create-phase',
			'do-create-phase',
			'thanks',
			'list',
			'change-status',
			'publish',
			'hide',
            'downloadskin',
            'downloadskindefault'
		);
		$acl->allow(Core_Role::ROLE_USER, $resource_name, $arrUser);
	}
	
	/**
	 *
	 * @param Zend_Acl $acl
	 */
	private function _initShareAcl($acl)
	{
		$resource_name = $this->_name . ':share';
		$acl->addResource($resource_name);
		$arrGuest = array(
			'share',		);
		$acl->allow(Core_Role::ROLE_GUEST, $resource_name);
	}
}

